package com.my.cloud.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.IdUtil;
import com.my.cloud.entities.Pay;
import com.my.cloud.resp.ResultData;
import com.my.cloud.service.PayService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Enumeration;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/3/12 8:58
 */
@RestController
@RequestMapping("/pay/gateway")
public class PayGateWayController {
    
    @Resource
    private PayService payService;
    
    @GetMapping("/get/{id}")
    public ResultData getById(@PathVariable("id") Integer id){
        Pay pay = payService.getById(id);
        return ResultData.success(pay);
    }
    
    @GetMapping("/info")
    public ResultData getGateWayInfo(){
        return ResultData.success("gateWay info test：" + IdUtil.simpleUUID());
    }
    
    @GetMapping("/filter")
    public ResultData getGateWayFilter(HttpServletRequest request){
        String result = "";
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            String headerName = headers.nextElement();
            String headerValue = request.getHeader(headerName);
            System.out.println("请求头名：" + headerName + "\t\t\t\t 请求头值：" + headerValue);
            if (headerName.equalsIgnoreCase("X-Request-atguigu1")
                    || headerName.equalsIgnoreCase("X-Request-atguigu2")){
                result = result + headerName + "\t" + headerValue + "";
            }
        }

        System.out.println("=================");
        String customerId = request.getParameter("customerId");
        System.out.println("customerId = " + customerId);
        String customerName = request.getParameter("customerName");
        System.out.println("customerName = " + customerName);
        System.out.println("=================");
        result += customerId;
        return ResultData.success("getGateWayFilter过滤器 test：" + result + " \t" + DateTime.now());
    }
    
}
